﻿<%@ Page Title="用户角色维护" Language="C#" MasterPageFile="~/masterPage/admin/Manage.master" AutoEventWireup="true" CodeFile="UsersAndRoles.aspx.cs" Inherits="Roles_UsersAndRoles" %>


<%@ MasterType VirtualPath="~/masterPage/admin/Manage.master" %>  


<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">

    <div>
        <table cellspacing="0" cellpadding="4" class="Retrieval">
            <tr class="Retrieval_T">
                <td  width="60" rowspan="2">
                    <font>显示<br />
                        条件</font>
                </td>
                <td  width="70">
                    <font>是否付费</font>
                </td>
                <td>
                    <font>用户名称</font>
                </td>
                <td>
                    <font>注册期间</font>
                </td>
                <td>
                    <font>使用期限期间</font>
                </td>
                <td width="80">
                    <font>条件设置</font>
                </td>
            </tr>
            <tr align="center" class="Retrieval_C">
                <td>
                    <asp:CheckBox ID="cbIsLockOut" runat="server"  Text="付费"/>
                </td>
                <td>
                    <asp:TextBox ID="tbUserName" CssClass="tb_RoleName" runat="server" MaxLength="20"></asp:TextBox>
                </td>
                <td>
                    <telerik:raddatepicker ID="dpCreateStDay" runat="server">
                    </telerik:raddatepicker>
                    <asp:Label ID="Label1" runat="server" Text="～"></asp:Label>
                    <telerik:raddatepicker ID="dpCreateEdDay" runat="server">
                    </telerik:raddatepicker>
                </td>
                <td>
                    <telerik:raddatepicker ID="dpLastLoginStDay" runat="server">
                    </telerik:raddatepicker>
                    <asp:Label ID="Label2" runat="server" Text="～"></asp:Label>
                    <telerik:raddatepicker ID="dpLastLoginEdDay" runat="server">
                    </telerik:raddatepicker>
                </td>
                <td>
                    <asp:Button ID="Btn_Set" CssClass="Btn_Set" runat="server" Text="索引" OnClick="Btn_Set_Click" />
                </td>
            </tr>
        </table>

                    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
            <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
            <telerik:RadGrid ID="rgridRoleUser" runat="server" AllowPaging="True" 
                AllowSorting="True" ShowStatusBar="True"   PageSize="10" 
                DataSourceID="sqlDSRoleUser" GridLines="Both" 
                onupdatecommand="rgridRoleUser_UpdateCommand" 
                    oninsertcommand="rgridRoleUser_InsertCommand" 
                onitemcommand="rgridRoleUser_ItemCommand" 
                ondeletecommand="rgridRoleUser_DeleteCommand"
                onitemcreated="rgridRoleUser_ItemCreated">
                <PagerStyle Mode="NumericPages" AlwaysVisible="true" />
<MasterTableView AutoGenerateColumns="False" DataKeyNames="UserId,RoleId" 
                    DataSourceID="sqlDSRoleUser"  EditMode="PopUp">
<NoRecordsTemplate>没有任何用户角色的数据！</NoRecordsTemplate>
    <Columns>
        <telerik:GridEditCommandColumn ButtonType="LinkButton">
            <HeaderStyle Width="4%" />
        </telerik:GridEditCommandColumn>
        <telerik:GridBoundColumn DataField="Email" 
            FilterControlAltText="Filter Email column" HeaderText="用户名" 
            SortExpression="Email" UniqueName="Email">
        </telerik:GridBoundColumn>
                    <telerik:GridDropDownColumn DataSourceID="sqlDSRoles" ListTextField="Description" ListValueField="RoleId"
                        UniqueName="RoleId" SortExpression="RoleId" HeaderText="角色" DataField="RoleId" DropDownControlType="RadComboBox">
        </telerik:GridDropDownColumn>
        <telerik:GridTemplateColumn DataField="ModerateDate" DataType="System.DateTime" 
            FilterControlAltText="Filter ModerateDate column" HeaderText="设置期限" 
            SortExpression="ModerateDate" UniqueName="ModerateDate">
            <ItemTemplate>
                <asp:Label ID="LblModerateDate" runat="server" Text='<% #Eval("ModerateDate","{0:yyyy/MM/dd}") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
                <telerik:RadDatePicker ID="RDPModerateDate" runat="server" SelectedDate='<% #Eval("ModerateDate") %>'>
                 </telerik:RadDatePicker>
            </EditItemTemplate>
        </telerik:GridTemplateColumn>

        <telerik:GridButtonColumn Text="删除" CommandName="Delete" ButtonType="ImageButton" ConfirmTitle="确认删除" ConfirmText="确认您要删除该用户角色吗？">
            <HeaderStyle Width="2%" />
        </telerik:GridButtonColumn>
    </Columns>

</MasterTableView>
            </telerik:RadGrid>
            </telerik:RadAjaxPanel>

    </div>
    <asp:SqlDataSource ID="sqlDSRoleUser" runat="server" 
        ConnectionString="<%$ ConnectionStrings:XunPanConnectionString %>" 
        SelectCommand="select  MS.UserId,UR.RoleId,MS.Email,R.mg_id,R.RoleName,
               (case R.RoleName
                when 'Purchase' then (case when CP.BuyerModerateDate <CONVERT (DateTime,'1980-01-01') then CONVERT (DateTime,'1980-01-01') else CP.BuyerModerateDate  end)
                when  'Suppliers' then (case when CP.VendorModerateDate<CONVERT (DateTime,'1980-01-01') then CONVERT (DateTime,'1980-01-01') else CP.VendorModerateDate end)
                else CONVERT (DateTime,'2099-01-01')
                end ) as ModerateDate
                from aspnet_Membership MS , XPCompany CP ,
                aspnet_Roles R 
                , aspnet_UsersInRoles UR
                where MS.UserId =CP.UserID and MS.UserId = UR.UserId and UR.RoleId=R.RoleId 
                and MS.Email like @userName and MS.CreateDate&gt;=@createStDay 
                and MS.CreateDate&lt;=@createEdDay and MS.LastLoginDate&gt;=@lastLoginStDay 
                and ((R.mg_id =2 and CP.IsApproved = 'True')
						or (R.mg_id =3 and CP.IsApproved = 'False'))
                and MS.LastLoginDate&lt;=@lastLoginEdDay 
union
select distinct MS.UserId,UR.RoleId,MS.Email,R.mg_id,R.RoleName,
                CONVERT (DateTime,'2099-01-01') as ModerateDate
                from aspnet_Membership MS , 
                aspnet_Roles R 
                , aspnet_UsersInRoles UR
                where  MS.UserId = UR.UserId and UR.RoleId=R.RoleId 
and MS.Email like @userName and MS.CreateDate&gt;=@createStDay 
                and MS.CreateDate&lt;=@createEdDay and MS.LastLoginDate&gt;=@lastLoginStDay 
and R.mg_id =1 and MS.LastLoginDate&lt;=@lastLoginEdDay
                ORDER BY MS.UserId" >
        <SelectParameters>
            <asp:ControlParameter ControlID="tbUserName" DefaultValue="%" Name="UserName" 
                PropertyName="Text" />
            <asp:Parameter DefaultValue="19000101" Name="createStDay" />
            <asp:Parameter DefaultValue="20991231" Name="createEdDay" />
            <asp:Parameter DefaultValue="19000101" Name="lastLoginStDay" />
            <asp:Parameter DefaultValue="20991231" Name="lastLoginEdDay" />
            <asp:Parameter DefaultValue="0" Name="isLocked" />
        </SelectParameters>
    </asp:SqlDataSource>

        <asp:SqlDataSource ID="sqlDSRoles" runat="server" 
            ConnectionString="<%$ ConnectionStrings:XunPanConnectionString %>" 
            
            SelectCommand="SELECT [RoleId], [RoleName], [Description] FROM [aspnet_Roles] ORDER BY [mg_id]">
         </asp:SqlDataSource>

</asp:Content>

